#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${package}.api;


import ${groupId}.core.contract.Page;
import ${groupId}.core.contract.R;
import ${package}.domain.contract.command.DemoDeleteCommand;
import ${package}.domain.contract.command.DemoImportExcelCommand;
import ${package}.domain.contract.command.DemoSaveCommand;
import ${package}.domain.contract.command.DemoUpdateCommand;
import ${package}.domain.contract.query.DemoDetailQuery;
import ${package}.domain.contract.query.DemoPageQuery;
import ${package}.domain.contract.vo.DemoExportExcelVO;
import ${package}.domain.demo.model.DemoBO;
import ${package}.domain.demo.service.DemoQueryService;
import ${package}.domain.demo.service.DemoService;
import ${groupId}.excel.annotation.ExportExcel;
import ${groupId}.excel.annotation.ImportExcel;
import ${groupId}.excel.annotation.Sheet;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author zhouhengzhe
 * @Desc Demo仓库，主要是给人去学习用(Demo)表控制层
 * @Date 2023-12-01 17:25:30
 */
@RestController
@RequestMapping("/demo")
@RequiredArgsConstructor
@Tag(name = "DemoController控制器")
public class DemoController {

    private final DemoService demoService;

    private final DemoQueryService demoQueryService;

    @Operation(summary = "增加demo")
    @PostMapping(path = "/addDemo")
    public R<Void> addDemo(@RequestBody @Validated DemoSaveCommand demoSaveCommand) {
        demoService.save(demoSaveCommand);
        return R.ok();
    }

    @Operation(summary = "删除demo")
    @PostMapping(path = "/removeDemo")
    public R<Void> removeDemo(@RequestBody @Validated DemoDeleteCommand demoDeleteCommand) {
        demoService.removeDemo(demoDeleteCommand);
        return R.ok();
    }

    @Operation(summary = "根据ID查询demo详情")
    @PostMapping(path = "/getDemoById")
    public R<DemoBO> getDemoById(@RequestBody @Validated DemoDetailQuery demoDetailQuery) {
        return R.ok(demoQueryService.getDemoById(demoDetailQuery));
    }

    @Operation(summary = "修改Demo")
    @PostMapping(path = "/updateDemo")
    public R<Void> updateDemo(@RequestBody @Validated DemoUpdateCommand demoUpdateCommand) {
        demoService.updateDemo(demoUpdateCommand);
        return R.ok();
    }

    @Operation(summary = "条件分页查询Demo")
    @PostMapping(path = "/pageDemo")
    public R<Page<DemoBO>> pageDemo(@RequestBody DemoPageQuery demoPageQuery) {
        return R.ok(demoQueryService.pageDemo(demoPageQuery));
    }

    @Operation(summary = "上传(excel头为用户名，年龄)")
    @PostMapping(path = "/uploadDemo")
    public R<Void> uploadDemo(@ImportExcel List<DemoImportExcelCommand> dataList) {
        demoService.uploadDemo(dataList);
        return R.ok();
    }

    @Operation(summary = "下载")
    @PostMapping(path = "/downloadDemo")
    @ExportExcel(name = "demo导出", sheets = @Sheet(sheetName = "demo"))
    public List<DemoExportExcelVO> downloadDemo(@RequestBody DemoPageQuery demoPageQuery) {
        return demoQueryService.downloadDemo(demoPageQuery);
    }

}
